<!doctype html>
<html lang="zh_cn">
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
	<button onclick="startHandler()">开启并发抢红包</button>
	<script>
  function ajax(obj) {
    let xhr = new XMLHttpRequest();
    xhr.timeout = 600000;
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4) {
        if (xhr.status == 200) {
          obj.success(xhr.responseText);
        } else {
          obj.error(xhr.response);
        }
      }
    };
    xhr.open("post", "userRedPacket/grapRedPacketForVersion.do");
    xhr.setRequestHeader("content-type", "application/json;charset=utf-8");
    xhr.send(JSON.stringify(obj.data));
  }

  function startHandler() {
	  console.time("开始");
	  for(let i = 0; i < 1000; i++){
		  ajax({
		      data: {
		        redPacketId: 1,
		        userId: i,
		      },
		      success(text) {
		        console.log(text);
		      },
		      error(err) {
		        console.log(err);
		      },
		    });
	  }
	  console.timeEnd("开始");
  }
</script>
</body>
</html>